package com.baojun.checkoutdemo;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.baojun.checkout.di.CheckoutBuilder;
import com.baojun.checkout.di.PayResult;
import com.baojun.checkout.di.PayResultPageAction;
import com.baojun.checkout.di.UserAction;

public class MainActivity extends AppCompatActivity {

    private EditText editId;
    private EditText editType;
    private Button btnShow;
    private EditText editSplitNo;
    private EditText editAmount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        editId = findViewById(R.id.edit_id);
        editId.setText("TE210915568700019");
        editType = findViewById(R.id.edit_type);
        editType.setText("28");
        btnShow = findViewById(R.id.btn_show);
        editSplitNo = findViewById(R.id.edit_split_no);
        editAmount = findViewById(R.id.edit_amount);

        btnShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (TextUtils.isEmpty(editAmount.getText())) {
                    editAmount.setText("0.0");
                }
                CheckoutBuilder builder = new CheckoutBuilder(MainActivity.this);
                builder.setorderNo(editId.getText().toString())
                        .setOrderType(editType.getText().toString())
                        .setSubOrderNo("")
                        .setSplitNo(editSplitNo.getText().toString())
                        .setOrderAmount(Double.parseDouble(editAmount.getText().toString()))
                        .setPayResultCallback(new PayResult() {
                            @Override
                            public void result(Activity activity, boolean b) {
                                //重写super方法，实现自定义页面跳转支付结果页面
//                                super.result(activity, b);
                            }
                        })
                        .setPayResultPageActionCallback(new PayResultPageAction() {
                            @Override
                            public void back(Activity activity) {
                                super.back(activity);
                            }

                            @Override
                            public void sure(Activity activity) {
                                super.sure(activity);
                            }
                        })
                        .setUserActionCallback(new UserAction() {
                            @Override
                            public void laterPay(Activity activity) {
                                super.laterPay(activity);
                            }

                            @Override
                            public void backCheckout(Activity activity) {
                                super.backCheckout(activity);
                            }
                        })
                        .show();
            }
        });
    }
}
